package com.txunda.zhuohired.aty.user.find;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ants.theantsgo.config.Settings;
import com.ants.theantsgo.gson.GsonUtil;
import com.ants.theantsgo.tool.ToolKit;
import com.ants.theantsgo.util.L;
import com.bumptech.glide.Glide;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.bean.user.find.FindDetailsBean;
import com.txunda.zhuohired.http.pst.MessagePst;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/6 14:57
 * 功能描述：发现详情
 * 联系方式：jiahuanchen@126.com
 */

public class FindInformationAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_find_information_center)
    private TextView tv_layout_find_information_center;
    /**
     * 标题
     */
    @ViewInject(R.id.tv_find_information_tittle)
    private TextView tv_find_information_tittle;
    /**
     * 类型
     */
    @ViewInject(R.id.tv_find_information_type)
    private TextView tv_find_information_type;
    /**
     * 浏览
     */
    @ViewInject(R.id.tv_find_information_look)
    private TextView tv_find_information_look;
    /**
     * 点赞
     */
    @ViewInject(R.id.tv_find_information_praise)
    private TextView tv_find_information_praise;
    /**
     * 内容
     */
    @ViewInject(R.id.tv_find_information_content)
    private TextView tv_find_information_content;
    /**
     * 图片
     */
    @ViewInject(R.id.iv_find_information_tittle)
    private ImageView iv_find_information_tittle;


    private String cate_id = "";
    private MessagePst messagePst;
    private int width;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_find_information_head);
        tv_layout_find_information_center.setText("详情");
        width = (Settings.displayWidth - ToolKit.dip2px(this, 24)) * 4 / 5; // 计算控件宽度
    }

    @Override
    @OnClick({R.id.iv_layout_find_information_share})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_layout_find_information_share://分享
                startActivity(ShareAty.class, null);
                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_find_information;
    }

    @Override
    protected void initialized() {
        cate_id = getIntent().getStringExtra("cate_id");
        messagePst = new MessagePst(this);
    }

    @Override
    protected void requestData() {
        messagePst.articleInfo(cate_id);
    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if (requestUrl.contains("articleInfo")) {
            L.e("=====articleInfo=====", jsonStr);
            FindDetailsBean findDetailsBean = GsonUtil.GsonToBean(jsonStr, FindDetailsBean.class);
            if (TextUtils.isEmpty(findDetailsBean.getData().getTitle())) {
                tv_find_information_tittle.setVisibility(View.GONE);
            } else {
                tv_find_information_tittle.setVisibility(View.VISIBLE);
                tv_find_information_tittle.setText(findDetailsBean.getData().getTitle());
            }
            if (TextUtils.isEmpty(findDetailsBean.getData().getType_name())) {
                tv_find_information_type.setVisibility(View.GONE);
            } else {
                tv_find_information_type.setVisibility(View.VISIBLE);
                tv_find_information_type.setText(findDetailsBean.getData().getType_name());
            }
            if (TextUtils.isEmpty(findDetailsBean.getData().getView())) {
                tv_find_information_look.setVisibility(View.GONE);
            } else {
                tv_find_information_look.setVisibility(View.VISIBLE);
                tv_find_information_look.setText(findDetailsBean.getData().getView());
            }
            if (TextUtils.isEmpty(findDetailsBean.getData().getGoods())) {
                tv_find_information_praise.setVisibility(View.GONE);
            } else {
                tv_find_information_praise.setVisibility(View.VISIBLE);
                tv_find_information_praise.setText(findDetailsBean.getData().getGoods());
            }
            if (TextUtils.isEmpty(findDetailsBean.getData().getContent())) {
                tv_find_information_content.setVisibility(View.GONE);
            } else {
                tv_find_information_content.setVisibility(View.VISIBLE);
                tv_find_information_content.setText(Html.fromHtml(findDetailsBean.getData().getContent()));
            }
            if (TextUtils.isEmpty(findDetailsBean.getData().getPic())) {
                iv_find_information_tittle.setVisibility(View.GONE);
            } else {
                ViewGroup.LayoutParams lp = iv_find_information_tittle.getLayoutParams();
                lp.width = Settings.displayWidth - ToolKit.dip2px(this, 24);
                lp.height = width;
                iv_find_information_tittle.setLayoutParams(lp);
                iv_find_information_tittle.setMaxWidth(Settings.displayWidth - ToolKit.dip2px(this, 24));
                iv_find_information_tittle.setMaxHeight(width);
                iv_find_information_tittle.setMinimumWidth(Settings.displayWidth - ToolKit.dip2px(this, 24));
                iv_find_information_tittle.setMinimumHeight(width);
                iv_find_information_tittle.setVisibility(View.VISIBLE);
                Glide.with(this).load(findDetailsBean.getData().getPic()).error(R.mipmap.icon_defult_bg).placeholder(R
                        .mipmap.icon_defult_bg).dontAnimate().into(iv_find_information_tittle);
            }
            return;
        }
    }
}
